Skip to content

fix(openai): preserve response output content index - #1437

Open
yaodong-shen wants to merge 1 commit into
AgentOps-AI:mainfrom
yaodong-shen:fix/openai-response-content-index
Open

fix(openai): preserve response output content index#1437
yaodong-shen wants to merge 1 commit into
AgentOps-AI:mainfrom
yaodong-shen:fix/openai-response-content-index

Conversation

@yaodong-shen

Copy link
Copy Markdown

📥 Pull Request

📘 Description

Fixes #1436.

OpenAI Responses can return a reasoning output before the assistant message. The message metadata correctly used its index in response.output, but nested ResponseOutputText attributes used the index within message.content. This placed message text under the preceding reasoning completion and left the actual message completion without content.

This change preserves the parent output index while extracting nested message text. The regression test uses the real OpenAI response models and verifies that a reasoning item at index 0 cannot absorb message content from index 1.

🧪 Testing

  • .venv/bin/python -m pytest tests/unit/instrumentation/openai_core/test_response_attributes.py -q -o log_cli=false — 14 passed
  • .venv/bin/python -m pytest tests/unit -q -o log_cli=false — 489 passed, 1 skipped
  • targeted Ruff check and format check — passed
  • project pre-commit hooks on both changed files — passed
  • git diff --check — passed

Use the parent output item's completion index for nested message content so reasoning outputs cannot absorb the following message text. Add coverage with real OpenAI response models.
for content in message.content:
if isinstance(content, ResponseOutputText):
attributes.update(get_response_output_text_attributes(content, i))
attributes.update(get_response_output_text_attributes(content, index))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve every text block in a response message

A ResponseOutputMessage.content list can legally contain multiple ResponseOutputText blocks. Passing the same parent index for each block makes every helper call emit gen_ai.completion.{index}.content, so attributes.update() silently replaces all earlier text with the last block. The helper also restarts each block's annotation index at j=0, causing later annotations to overwrite earlier ones under the same completion. Please aggregate the text blocks in order and keep annotation indices unique across the whole message (with offsets consistent with the aggregated content), and add a regression containing two annotated output_text blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI Responses message content uses the wrong completion index

2 participants